/**
 * Copyright (c) Software Institute of PKU
 * All rights reserved. 
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 */
package edu.pku.sei.modeler.ui.dnd;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.eclipse.gef.requests.CreationFactory;

import edu.pku.sei.modeler.model.core.MetaElement;
import edu.pku.sei.modeler.model.core.MetaModelElement;

/**
 * @author zl
 * @modifiedby fengchao
 */
public class DropElementCreationFactory implements CreationFactory {
	private List<MetaElement> elements = new ArrayList<MetaElement>();
	private int index = 0;
	public DropElementCreationFactory() {
	}
	/* (non-Javadoc)
	 * @see org.eclipse.gef.requests.CreationFactory#getNewObject()
	 */
	public Object getNewObject() {
		if (index < elements.size()) {
			MetaElement element = elements.get(index);
			index ++;
			return element;
		} else {
			return null;
		}
	}

	/* (non-Javadoc)
	 * @see org.eclipse.gef.requests.CreationFactory#getObjectType()
	 */
	public Object getObjectType() {
		return MetaModelElement.class;
	}

	public void addElement(MetaModelElement element) {
		this.elements.add(element);
	}
	
	public void setElements(Collection elements) {
		for (Object object : elements) {
			if (object instanceof MetaElement) {
				this.elements.add((MetaElement) object);
			}
		}
	}
}
